package main.java.indi.zyj.coderecord;

import main.java.indi.zyj.hot100.base.TreeNode;

import java.util.Stack;

public class GetMinimumDifference {

    public int getMinimumDifference(TreeNode root) {

        int diff = Integer.MAX_VALUE;
        TreeNode pre = null;

        Stack<TreeNode> stack = new Stack<>();

        while (!stack.isEmpty() || root != null) {
            if (root != null) {
                stack.add(root);
                root = root.left;
            } else {
                root = stack.pop();
                if(pre != null)
                    diff = Math.min(diff, root.val - pre.val);
                pre = root;
                root = root.right;
            }
        }
        return diff;
    }

}
